<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal">
                    <div class="form-group">
                        <label class="control-label col-sm-1">柜型:</label>
                        <div class="col-sm-2">
                            <select  id="freightCabinetName" name="freightCabinetName" class="form-control">
                                <option value="">请选择</option>
                                <%for(var dict in cabinet){%>
                                <option value="${dict.cabinetName}">${dict.cabinetName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">运输方式:</label>
                        <div class="col-sm-2">
                            <select  name="freightTrans" class="form-control">
                                <option value="">请选择</option>
                                <%for(var dict in transport){%>
                                <option value="${dict.transportName}">${dict.transportName}</option>
                                <%}%>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-sm-1">发运港:</label>
                        <div class="col-sm-2">
                            <select   name="fromPortName" class="form-control">
                                <option value="">请选择</option>
                                <%for(var dict in port){%>
                                <option value="${dict.portName}">${dict.portName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">目的港:</label>
                        <div class="col-sm-2">
                            <select id="toPortName" name="toPortName" class="form-control">
                                <option value="">请选择</option>
                                <%for(var dict in port){%>
                                <option value="${dict.id}">${dict.portName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">目的港仓库:</label>
                        <div class="col-sm-2">
                            <select id="toWareName"  name="toWareName" class="form-control">

                            </select>
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
            <!-- START 操作按钮 -->
            <form>
                <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                    <button  class="add-btn layui-btn layui-btn-normal layui-btn-sm" >
                        <i class="fa fa-plus" aria-hidden="true"></i> 新增
                    </button>
                    <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -1px;margin-left: -4px">
                        <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                    </button>
                </div>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="freightTable"
                   data-toolbar="#toolbar"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-url="/sea/physical/freight/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>

            <!-- END 数据表格 -->
        </div>
    </div>
</div>
<!-- START 数据表格 -->

<!-- END 数据表格 -->
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer'}){}%>
<script>
    var $freightTable = $('#freightTable');
    $(function () {
        // START 表格配置
        $freightTable.bootstrapTable({
            pageSize:10,
            columns: [
                {
                    title: '柜型',
                    field: 'freightCabinetName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '运输方式',
                    field: 'freightTrans',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发运港',
                    field: 'fromPortName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '目的港',
                    field: 'toPortName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '目的港仓库',
                    field: 'toWareName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总运费',
                    field: 'freightTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '分摊方式',
                    field: 'freightType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                // 删除
                $('.edit-freight-btn').on('click',function () {
                    var id = $(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/physical/freight/editPage.do?id='+id, 'yes']
                    });
                });

                // 删除
                $('.del-freight-btn').on('click',function () {
                    var id = $(this).attr('data-val');
                    layer.confirm('确定删除？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/physical/freight/delete.do',{id: id},function(data){
                            if( data.ok ){
                                $("#freightTable").bootstrapTable('refresh');
                                layer.msg(data.msg,{icon: 1,time: 1500});
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });

                $('.record-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        type: 2,
                        closeBtn:false,
                        area: ['100%','100%'],
                        content: ['/sea/physical/freight/record/main.do?id='+id, 'yes']
                    });
                });
            }
        });
    });

    // 操作菜单
    function optFormatter(value,row){
        var content = '<button class="edit-freight-btn btn btn-xs btn-info" data-val="'+row.id+'" title="修改"><i class="fa fa-edit"></i>  </button>&nbsp;';
        content += '<button class="del-freight-btn btn btn-xs btn-danger" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i>  </button>';
        content+= '<button class="record-btn btn btn-xs btn-default" style="margin-left: 5px;" data-val="'+row.id+'" title="价格变动记录">价格变动记录</button>';
        return content;
    }

    $("#toPortName").change(function () {
        var parentId=$("#toPortName").val();
        getCategory(parentId);
    });

    function getCategory(parentId) {
        $.ajax({
            url:'/sea/physical/port/findByParenId',
            data:{
                id:parentId
            },
            type:'post',
            success:function (data) {
                var list=data;
                console.log(list);
                if(list.length>0){
                    var category='<option value="">全部分类</option>';
                    for(var i=0;i<list.length;i++){
                        category+='<option value="'+list[i].portName+'">'+list[i].portName+'</option>';
                    }
                    $("#toWareName").html(category);
                }
            }
        });
    }

    //新增
    $('.add-btn').on('click',function(){//新增
        layer.open({
            type: 2,
            area: ['100%','100%'],
            skin: 'layer-ext-espresso',
            content: ['/sea/physical/freight/addPage.do', 'yes']
        });
    });

    // 条件查询
    $('.search-btn').on('click',function () {
        $freightTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/physical/freight/findByCnd.do?'+$('#search-form').serialize() });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/physical/freight/export.do?'+$('#search-form').serialize();
    });
</script>
</body>
</html>
